package com.zhang.mapper;

import com.zhang.pojo.Article;
import org.apache.ibatis.annotations.*;
import org.springframework.web.bind.annotation.DeleteMapping;

import java.util.List;

/**
 * @program: big_event
 * @description: TODO
 * @author: Mr.Zhang
 * @create: 2024-04-06 13:48
 **/
@Mapper
public interface ArticleMapper {

    /**
     * 新增 该接口用于新增文章(发布文章)
     *
     * @param article
     */
    @Insert("insert into article(title,content,cover_img,state,category_id,create_user,create_time,update_time) " +
            "values(#{title},#{content},#{coverImg},#{state},#{categoryId},#{createUser},#{createTime},#{updateTime})")
    void add(Article article);

    /**
     * 条件分页列表查询
     * 该接口用于根据条件查询文章,带分页
     *
     * @param userId
     * @param categoryId
     * @param state
     * @return
     */
    List<Article> list(Integer userId, Integer categoryId, String state);

    /**
     * 获取文章详情
     *
     * @param id
     * @return
     */
    @Select("select * from article where id = #{id}")
    Article detail(Integer id);


    /**
     * 更新文章信息
     * @param article
     */
    @Update("update article set title = #{title}, content = #{content}, cover_img = #{coverImg}, state = #{state}, category_id = #{categoryId},update_time = #{updateTime} where id=#{id}")
    void update(Article article);

    /**
     * 根据ID删除文章
     * @param id
     */
    @Delete("delete from article where id = #{id}")
    void delete(Integer id);
}
